/*
 * @Author: 黑白灰01 3193273703@qq.com
 * @Date: 2025-09-01 15:20:26
 * @LastEditors: 黑白灰01 3193273703@qq.com
 * @LastEditTime: 2025-09-01 15:20:33
 * @FilePath: /hei-oa/src/common/dto/pagination-response.dto.ts
 * @Description: 分页响应 DTO
 */
// src/common/dto/pagination-response.dto.ts
import { ApiProperty } from '@nestjs/swagger';
import { PaginationDto } from 'src/common/dto/pagination.dto';

export class PaginationResponseDto<T> {
  @ApiProperty({ description: '总记录数' })
  total: number;

  @ApiProperty({ description: '当前页码' })
  page: number;

  @ApiProperty({ description: '每页记录数' })
  pageSize: number;

  @ApiProperty({ description: '总页数' })
  totalPages: number;

  @ApiProperty({ description: '是否有下一页' })
  hasNextPage: boolean;

  @ApiProperty({ description: '是否有上一页' })
  hasPrevPage: boolean;

  @ApiProperty({ description: '数据列表' })
  items: T[];

  constructor(
    items: T[],
    total: number,
    paginationDto: PaginationDto
  ) {
    const { page, pageSize } = paginationDto;
    this.items = items;
    this.total = total;
    this.page = page;
    this.pageSize = pageSize;
    this.totalPages = Math.ceil(total / pageSize);
    this.hasNextPage = page < this.totalPages;
    this.hasPrevPage = page > 1;
  }
}